using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using eShop.Business;
using eShop.Model;
using ECommerce.Library;
using eShop.Business;
using eShop.Utility;
using System.Web.Services;
using System.Collections.Generic;


public partial class controls_wucCategoryLeftMenu : BaseControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rCategoryMenu.DataSource = CategoryManager.GetRootCategories();
            rCategoryMenu.DataBind();
        }
    }

    protected void rCategoryMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Category category = (Category)e.Item.DataItem;
            Repeater rSubCategory = (Repeater)e.Item.FindControl("rSubCategory");
            List<Category> categories = CategoryManager.GetActiveSubCategories(category.Id);
            rSubCategory.DataSource = categories;
            rSubCategory.DataBind();
            rSubCategory.Visible = categories.Count > 0;
        }
    }

    protected void rSubCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Category category = (Category)e.Item.DataItem;
            Repeater rSubSubCategory = (Repeater)e.Item.FindControl("rSubSubCategory");
            List<Category> categories = CategoryManager.GetActiveSubCategories(category.Id);
            rSubSubCategory.DataSource = categories;
            rSubSubCategory.DataBind();
            rSubSubCategory.Visible = categories.Count > 0;
        }
    }
    
}
